package com.yida.system.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.yida.common.core.constant.CacheConstants;
import com.yida.common.redis.service.RedisService;
import com.yida.system.domain.SysConfig;
import com.yida.system.mapper.SysConfigMapper;

/**
 * @Description 系统配置
 * @Author wws
 * @Date 2023-03-21
 */
@Configuration
// @RequiredArgsConstructor
public class SysEnableConfig {

    @Autowired
    private SysConfigMapper sysConfigMapper;

    @Autowired
    private RedisService redisService;

    @Bean
    public void initSysConfig() {
        SysConfig sysConfig = new SysConfig();
        sysConfig.setConfigKey(CacheConstants.SYS_CONFIG_BLACK_WHITE_KEY);
        // 查询系统服务
        List<SysConfig> sysConfigList = sysConfigMapper.selectConfigList(sysConfig);
        // 加入缓存
        sysConfigList.forEach(item -> {
            redisService.setCacheObject(CacheConstants.SYS_CONFIG_KEY + CacheConstants.SYS_CONFIG_BLACK_WHITE_KEY,
                item.getConfigValue());
        });
    }

}
